package org.devocean.groupbuying.utils;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


public class RenderMapUtils {
	
	
	/**
	 * Generates modelMap to return in the modelAndView
	 * @author Mohsine DANI
	 * @param Generic List
	 * @return modelMap
	 */
	public static <T> Map<String,Object> getMap(List<T> datas, long total){
		
		Map<String,Object> modelMap = new ConcurrentHashMap<String, Object>(3); //thread safe map
		modelMap.put("total", total);
		modelMap.put("data", datas);
		modelMap.put("success", true);
		
		return modelMap;
	}
	
public static <T> Map<String,Object> getMapChildren(List<T> datas){
		
		Map<String,Object> modelMap = new ConcurrentHashMap<String, Object>(3); //thread safe map
		modelMap.put("children", datas);
		modelMap.put("success", true);
		
		return modelMap;
	}
	
	/**
	 * Generates modelMap to return in the modelAndView
	 * @author Mohsine DANI
	 * @param Generic Object
	 * @return modelMap
	 */
	public static <T> Map<String,Object> getMap(T data){
		
		Map<String,Object> modelMap = new ConcurrentHashMap<String, Object>(2); //thread safe map
		modelMap.put("data", data);
		modelMap.put("success", true);
		
		return modelMap;
	}
	
	/**
	 * Generates modelMap to return in the modelAndView in case
	 * of exception
	 * @author Mohsine DANI
	 * @param msg message
	 * @return modelMap
	 */
	public static Map<String,Object> getModelMapError(String msg){

		Map<String,Object> modelMap = new ConcurrentHashMap<String, Object>(2); //thread safe map
		modelMap.put("message", msg);
		modelMap.put("success", false);
		
		return modelMap;
	} 
	
	

}
